package com.ljx.qqpro.config;

import com.ljx.qqpro.service.ChatRecordService;
import com.ljx.qqpro.service.ChatService;
import com.ljx.qqpro.service.ChatUserService;
import com.ljx.qqpro.websocket.ChatListInfoWebSocket;
import com.ljx.qqpro.websocket.ChatWebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
public class WebSocketConfig {
    /**
     * 	注入ServerEndpointExporter，
     * 	这个bean会自动注册使用了@ServerEndpoint注解声明的Websocket endpoint
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    /**
     * 注入service
     * @param chatService
     */
    @Autowired
    private void setChatService(ChatService chatService){
        ChatWebSocket.chatService = chatService;
        ChatListInfoWebSocket.chatService = chatService;
    }

    @Autowired
    private void setChatUserService(ChatUserService chatUserService){
        ChatWebSocket.chatUserService = chatUserService;
        ChatListInfoWebSocket.chatUserService = chatUserService;
    }

    @Autowired
    private void setChatRecord(ChatRecordService chatRecordService){
        ChatWebSocket.chatRecordService = chatRecordService;
    }

}
